<template>
    <div class="modal fade" id="exit_box" tabindex="-1" role="dialog"
         aria-labelledby="exit_box">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-body">
                    <div class="exit_box">
                        <div class="login-form">
                            <div class="exit_top">
                                <p class="exit_top_text">您将退出账号？</p>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-success" @click="loginOut">确定</button>
                    <button type="button" class="btn btn-success export" data-dismiss="modal">取消</button>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        methods: {
            loginOut () {
                let data = {
                    email: this.$store.state.adminInfo.userEmail
                }
                this.$ajax
                    .autoService
                    .logout(data)
                    .then((res) => {
                        let result = res.data
                        if (result.code === 200) {
                            $('#exit_box').modal('hide')
                            let timer = setTimeout(() => {
                                clearTimeout(timer)
                                this.$router.push({path: '/login'})
                            }, 500)
                        } else if (result.code === 408) {
                            this.$store.commit('showAlert', {error: this.$msgDictionary.loginGetaway})
                            let timer = setTimeout(() => {
                                clearTimeout(timer)
                                $('#msgModal').modal('hide')
                                $('#exit_box').modal('hide')
                                this.$router.push({path: '/login'})
                            }, 2000)
                        } else {
                            this.$store.commit('showAlert', {error: result.msg})
                        }
                    }, () => {
                        this.$store.commit('showAlert', {error: this.$msgDictionary.serviceException})
                        let timer = setTimeout(() => {
                            clearTimeout(timer)
                            $('#msgModal').modal('hide')
                            $('#exit_box').modal('hide')
                            this.$router.push({path: '/login'})
                        }, 2000)
                    })
            },
        }
    }
</script>

<style scoped>
    .modal-content {
        width: 429px;
        height: 280px;
    }

    .exit_box {
        height: 183px;
        position: relative;
        overflow: scroll;
        overflow-x: hidden;
        overflow-y: hidden;
        text-align: center;
    }

    .modal-body {
        color: white;
        background: #263238;
        height: 183px;
    }

    .exit_top_text {
        text-align: center;
        line-height: 160px;
        font-size: 14px;
    }

    .modal-footer {
        padding-top: 30px;
    }
</style>
